# -*- coding: utf-8 -*-
# Author: xiantingDeng
# Email: dengxianting@shxgroup.net
# Time: 2020/8/20 9:34


import time
import re
import allure
from appium.webdriver.common.touch_action import TouchAction


class TheKeyboard():
    def __init__(self, driver, log):
        self.__driver = driver
        self.__log = log

    # todo 设置手势密码 等待修改 未完成
    def set_gesture_pwd(self, swipepassword):
        '''
        设置手势密码
        :param swipepassword: 输入密码 
        :return: 
        '''
        with allure.step("正在进行手势密码设置or登录：{}".format(swipepassword)):
            try:
                height = self.__driver.get_windwow_size()["height"]
                width = self.__driver.get_windwow_size()["width"]
                x = 1080 / width
                y = 2040 / height
                dic = {
                    '1': [int(238 * x), int(767 * y)],
                    '2': [int(528 * x), int(755 * y)],
                    '3': [int(840 * x), int(755 * y)],
                    '4': [int(235 * x), int(1067 * y)],
                    '5': [int(535 * x), int(1060 * y)],
                    '6': [int(848 * x), int(1056 * y)],
                    '7': [int(246 * x), int(1368 * y)],
                    '8': [int(539 * x), int(1364 * y)],
                    '9': [int(844 * x), int(1353 * y)]
                }
                dev = "device()" #
                strSwipe = []
                for i in swipepassword:
                    get = dic.get(i)
                    strSwipe.append(get)
                dev.swipe_along(strSwipe)
                self.__log.debug("设置手势密码【{}】成功".format(swipepassword))
            except Exception as e:
                raise

